package cn.zk;

import org.apache.zookeeper.KeeperException;

import java.io.IOException;
import java.util.List;

public class ListGroup extends ConnectionWatcher{

    public void list(String groupName){
        String path = "/" + groupName;

        try {
            List<String> children = zk.getChildren(path,false);
            if(children.isEmpty()){
                System.out.printf("No members in group %s\n",groupName);
                System.exit(1);
            }
            for(String child : children){
                System.out.println(child);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (KeeperException e) {
            System.out.printf("Group %s does not exist\n",groupName);
            System.exit(1);
        }
    }

    public static void main(String[] args) throws InterruptedException, IOException {
        ListGroup listGroup = new ListGroup();
        listGroup.connect("mini1");
        listGroup.list("zookeeper/quota");
        listGroup.close();
    }

}
